import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:test01/okhttp_test/page/indexlogin/login_main.dart';
import 'package:test01/okhttp_test/page/pages/okhttp_main.dart';
import 'package:test01/okhttp_test/page/pages/search.dart';
import 'package:test01/okhttp_test/pojo/login_request_pojo.dart';
import 'package:test01/okhttp_test/pojo/rewrite/mytabindicator.dart';
import 'package:test01/okhttp_test/pojo/rewrite/mytabs.dart' as newtabs;
import 'package:test01/okhttp_test/provider/searchwords.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

void main() => runApp(
    ChangeNotifierProvider(
      create: (_) => IsFollow(),
        child:MyApp(),
    )
);




class MyApp extends StatefulWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    ///禁止程序横屏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp, //只能纵向
      DeviceOrientation.portraitDown, //只能纵向
    ]);

    return MaterialApp(
      home: TabBarViewPage(),
    );
  }
}

class TabBarViewPage extends StatefulWidget {
  @override
  TabBarViewPageState createState() => TabBarViewPageState();
}

class TabBarViewPageState extends State<TabBarViewPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  final List<String> tabValues = [
    '关注',
    '推荐',
  ];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: tabValues.length);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0, //去掉阴影
        backgroundColor: Colors.amber, //修改背景颜色
        title: Row(
          children: <Widget>[
            GestureDetector(
              onTap: () {
                ///跳转不关闭当前页面
                Navigator.of(context).push(MaterialPageRoute(builder: (context) {return PageOne();},),);
              },
              child: Container(
                child: Icon(
                  Icons.add_a_photo_outlined,
                  size: 28,
                  color: Colors.black.withOpacity(0.5),
                ),
              ),
            ),
            Container(
              width: MediaQuery.of(context).size.width - 88,
              alignment: Alignment.center,
              child: newtabs.TabBar(
                tabs: <Widget>[
                  Text("关注"),
                  Text("推荐"),
                ],
                controller: _tabController,
                indicatorColor: Colors.red,
                indicator: MyUnderlineTabIndicator(
                    borderSide: BorderSide(width: 2.0, color: Colors.red)),

                ///选中标签的样式以及颜色
                labelStyle: TextStyle(fontSize: 18),
                labelColor: Colors.black,
                unselectedLabelStyle: TextStyle(fontSize: 16),

                ///未选中标签样式以及颜色
                unselectedLabelColor: Colors.black.withOpacity(0.5),
              ),
            ),
            Spacer(),
            GestureDetector(
              onTap: () {
                ///跳转不关闭当前页面
                Navigator.of(context).push(MaterialPageRoute(builder: (context) {return SearchPage();},),);
              },
              child: Container(
                child: Icon(
                  Icons.zoom_out_rounded,
                  size: 28,
                  color: Colors.black.withOpacity(0.5),
                ),
              ),
            ),
          ],
        ),
      ),

      body: newtabs.TabBarView(
        controller: _tabController,
        children: <Widget>[
          ///关注界面
          vidoList(),

          ///推荐界面
          Center(child: Text("这是推荐的内容")),
        ],
      ),
    );
  }
}
